function reallocGeometricObject(p,n)
  use derived,only:GeometricObject
  implicit none

  type(GeometricObject),pointer,dimension(:) :: &
       reallocGeometricObject,p
  integer,intent(in) :: n
  
  integer :: i,ierr,gtype

  allocate(reallocGeometricObject(1:n),stat=ierr)

  if (ierr.ne.0) call abnormal_stop("reallocGeometricObject",&
       "Memory allocation causes an error.")

  do i=1,n
     nullify(reallocGeometricObject(i)%diss_eb)
     nullify(reallocGeometricObject(i)%diss_nu)
     nullify(reallocGeometricObject(i)%diss_rd)
     nullify(reallocGeometricObject(i)%diss_const_rate)
     nullify(reallocGeometricObject(i)%diss_n)
     nullify(reallocGeometricObject(i)%diss_obj)
     reallocGeometricObject(i)%does_diss=.false.
     reallocGeometricObject(i)%diss_type=0
     reallocGeometricObject(i)%n_diss_react_group=0
     nullify(reallocGeometricObject(i)%diss_react_group)
  end do

  if (.not.associated(p)) return

  do i=1,n-1
     gtype=p(i)%geom_type
     reallocGeometricObject(i)%index=p(i)%index
     reallocGeometricObject(i)%geom_type=gtype
     select case(gtype)
     case(1)
        ! point
        reallocGeometricObject(i)%x1=p(i)%x1
        reallocGeometricObject(i)%y1=p(i)%y1
        reallocGeometricObject(i)%z1=p(i)%z1
     case(2)
        ! line
        reallocGeometricObject(i)%x1=p(i)%x1
        reallocGeometricObject(i)%y1=p(i)%y1
        reallocGeometricObject(i)%z1=p(i)%z1
        reallocGeometricObject(i)%x2=p(i)%x2
        reallocGeometricObject(i)%y2=p(i)%y2
        reallocGeometricObject(i)%z2=p(i)%z2
     case(3)
        ! x=a,left
        reallocGeometricObject(i)%x1=p(i)%x1
        reallocGeometricObject(i)%y1=p(i)%y1
        reallocGeometricObject(i)%z1=p(i)%z1
        reallocGeometricObject(i)%y2=p(i)%y2
        reallocGeometricObject(i)%z2=p(i)%z2
     case(4)
        ! x=a,right
        reallocGeometricObject(i)%x1=p(i)%x1
        reallocGeometricObject(i)%y1=p(i)%y1
        reallocGeometricObject(i)%z1=p(i)%z1
        reallocGeometricObject(i)%y2=p(i)%y2
        reallocGeometricObject(i)%z2=p(i)%z2
     case(5)
        ! y=b,left
        reallocGeometricObject(i)%x1=p(i)%x1
        reallocGeometricObject(i)%y1=p(i)%y1
        reallocGeometricObject(i)%z1=p(i)%z1
        reallocGeometricObject(i)%x2=p(i)%x2
        reallocGeometricObject(i)%z2=p(i)%z2
     case(6)
        ! y=b,rigth
        reallocGeometricObject(i)%x1=p(i)%x1
        reallocGeometricObject(i)%y1=p(i)%y1
        reallocGeometricObject(i)%z1=p(i)%z1
        reallocGeometricObject(i)%x2=p(i)%x2
        reallocGeometricObject(i)%z2=p(i)%z2
     case(7)
        ! z=c,left
        reallocGeometricObject(i)%x1=p(i)%x1
        reallocGeometricObject(i)%y1=p(i)%y1
        reallocGeometricObject(i)%z1=p(i)%z1
        reallocGeometricObject(i)%x2=p(i)%x2
        reallocGeometricObject(i)%y2=p(i)%y2
     case(8)      
        ! z=c,right
        reallocGeometricObject(i)%x1=p(i)%x1
        reallocGeometricObject(i)%y1=p(i)%y1
        reallocGeometricObject(i)%z1=p(i)%z1
        reallocGeometricObject(i)%x2=p(i)%x2
        reallocGeometricObject(i)%y2=p(i)%y2
     case default
        call abnormal_stop("reallocGeometricObject",&
             "Unrecognized type of geometrical object is found.")
     end select

  end do

  deallocate(p)

  return

end function reallocGeometricObject
